home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.2 Applications 1996 May / SGI IRIX 6.2 Applications 1996 May.iso / dist / impr_dev.idb / usr / impressario / src / examples / libpod / readlog.c.z / readlog.c
C/C++ Source or Header  |  1996-05-06  |  3KB  |  117 lines

  1. /**************************************************************************
  2.  *
  3.  *           Copyright (c)    1992 Silicon Graphics, Inc.
  4.  *            All Rights Reserved
  5.  *
  6.  *       THIS    IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI
  7.  *
  8.  * The copyright notice above does not evidence any actual of intended
  9.  * publication of such source code, and is an unpublished work by Silicon
  10.  * Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is
  11.  * the property of Silicon Graphics, Inc. Any use, duplication or
  12.  * disclosure not specifically authorized by Silicon Graphics is strictly
  13.  * prohibited.
  14.  *
  15.  * RESTRICTED RIGHTS LEGEND:
  16.  *
  17.  * Use, duplication or disclosure by the Government is subject to
  18.  * restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
  19.  * Technical Data and Computer Software clause at DFARS 52.227-7013,
  20.  * and/or in similar or successor clauses in the FAR, DOD or NASA FAR
  21.  * Supplement. Unpublished - rights reserved under the Copyright Laws of
  22.  * the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.
  23.  * Shoreline Blvd., Mountain View, CA 94039-7311
  24.  **************************************************************************
  25.  *
  26.  * File: readlog.c
  27.  *
  28.  * Description: Sample program that demonstrates the use of the standard
  29.  *    form of the libpod log file read function.
  30.  *
  31.  *    Usage: readlog printer_name [num_lines]
  32.  *
  33.  *    If num_lines is not specified, the entire log file will be read
  34.  *    and display on standard out. If num_lines is specified, the last
  35.  *    num_lines lines of the log file will be read and displayed.
  36.  *
  37.  **************************************************************************/
  38.  
  39.  
  40. #ident "$Revision: 1.1 $"
  41.  
  42.  
  43. #include <stdio.h>
  44. #include <string.h>
  45. #include <stdlib.h>
  46. #include <time.h>
  47. #include <pod.h>
  48.  
  49.  
  50. #define HANDLE_ERROR(pname)    { \
  51.                 PDPerror(pname); \
  52.                 exit(1); \
  53.                 }
  54.  
  55.  
  56. void usage(char*);
  57.  
  58.  
  59. int main(int argc, char **argv)
  60. {
  61.     PDLogStruct *entries;
  62.     time_t mod_time;
  63.     char *printer_name;
  64.     char time_str[50];
  65.     int num_lines, actual_num;
  66.     register int i;
  67.  
  68.     /*
  69.      * Get the printer name and number of lines
  70.      * from command line
  71.      */
  72.     if (argc < 2) {
  73.     usage(argv[0]);
  74.     exit(1);
  75.     }
  76.     printer_name = argv[1];
  77.     if (argc == 3)
  78.     num_lines = strtol(argv[2], (char**)NULL, 0);
  79.     else
  80.     num_lines = PD_LOG_ALL;
  81.  
  82.     /*
  83.      * Read log file
  84.      */
  85.     if ((actual_num = PDReadLog(printer_name, num_lines,
  86.                     &entries, &mod_time)) < 0)
  87.     HANDLE_ERROR(argv[0]);
  88.  
  89.     /*
  90.      * Display the log file entries
  91.      */
  92.     (void)printf("Last modified: %s\n", ctime(&mod_time));
  93.     for (i = 0; i < actual_num; i++) {
  94.     (void)cftime(time_str, "%b %d %T", &(entries[i].time_stamp));
  95.     (void)printf("%s: ", time_str);
  96.     if (entries[i].job_id)
  97.         (void)printf("%s ", entries[i].job_id);
  98.     else
  99.         (void)printf("* ");
  100.     if (entries[i].username)
  101.         (void)printf("%s ", entries[i].username);
  102.     else
  103.         (void)printf("* ");
  104.     (void)printf("0x%X ", entries[i].entry.message_code);
  105.     (void)printf("%s\n", entries[i].entry.message_text);
  106.     }
  107.  
  108.     return 0;
  109. }
  110.  
  111.  
  112. void usage(char *progname)
  113. {
  114.     (void)fprintf(stderr, "Usage: %s printer_name [num_lines]\n", progname);
  115. }
  116.  
  117.